package com.cet.beanmap.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author 30952
 * 创建一个用于监听指定事件的类，需要实现ApplicationListener接口，
 * 说明它是一个应用程序事件的监听类。注意这里需要加上@Component注解，将其注入Spring容器中。
 */
@Component
public class MyListener implements ApplicationListener<Event> {
    private static final Logger logger= LoggerFactory.getLogger(MyListener.class);

    @Async
    @Override
    public void onApplicationEvent(Event event) {
        logger.info("listener get event,sleep 2 second...");
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        logger.info("event msg is:{}",event.getMsg());
    }
}
